package com.goods.business.converter;


import com.goods.business.service.SupplierService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/business/supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    //物资来源分页列表展示
    @GetMapping("/findSupplierList")
    public ResponseBean findSupplierList(@RequestParam Integer pageNum,
                                         @RequestParam Integer pageSize,
                                         @RequestParam String name,
                                         @RequestParam(required = false) String address,
                                         @RequestParam(required = false) String contact){
        PageVO<SupplierVO> pageVO = supplierService.findSupplierList(pageNum,pageSize,name,address,contact);
        return ResponseBean.success(pageVO);
    }

    //添加物资来源
    @PostMapping("/add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO){
        supplierService.add(supplierVO);
        return ResponseBean.success();
    }

    //编辑物资来源
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        SupplierVO supplierVO = supplierService.edit(id);
        return ResponseBean.success(supplierVO);
    }

    //修改物资来源
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody SupplierVO supplierVO){
        supplierService.update(id,supplierVO);
        return ResponseBean.success();
    }

    //删除物资来源
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        supplierService.delete(id);

        return ResponseBean.success();
    }
}
